$(function() {

    var LoginView = Backbone.View.extend({
        el: $("#login-form"),
        events: {"click #login": "login"},
        initialize: function() {

        },
        login: function() {
            var url = 'api/login';

            var formValues = {
                user: $("#username").val(),
                pword: $("#password").val()
            };

            $.ajax({
                url: url,
                type: 'POST',
                dataType: "json",
                data: formValues,
                success: function(data) {
                    console.log(["Login request details: ", data]);

                    if (data.error) {  // If there is an error, show the error messages
                        $('.alert-error').text(data.error.text).show();
                    }
                    else { // If not, send them back to the home page
                        window.location = 'main.php';
                    }
                }
            });
            return false;
        }
    });

    var login_view = new LoginView();

    $("#username").val("");
    $("#password").val("");
    $("#username").focus();
});




           